package com.ruoyi.web.controller.front;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/notice")
public class NoticeController {


    @Autowired
    private ISysNoticeService noticeService;



    @GetMapping("applet/getNoticesPage")
    public AjaxResult getNoticesPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                     String noticeType){
        PageHelper.startPage(pageNum, pageSize);
        SysNotice notice = new SysNotice();
        notice.setNoticeType(noticeType);
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        PageInfo<SysNotice> pageInfo = new PageInfo<>(list);
        return AjaxResult.success(pageInfo);
    }


    @GetMapping("applet/getNoticesById")
    public AjaxResult getNoticesById(Long id){
        SysNotice notice = noticeService.selectNoticeById(id);
        return AjaxResult.success(notice);
    }

}
